No title

BATHULA PRAVEEN (BP)
0

 



#1.Start by visualizing some data points:

import matplotlib.pyplot as plt

x = [4, 5, 10, 4, 3, 11, 14 , 6, 18, 12]

y = [21, 19, 24, 17, 16, 25, 24, 22, 21, 21]

plt.scatter(x, y)

plt.show()





from sklearn.cluster import KMeans

data = list(zip(x, vy))

inertias = []

for i in range(1,11):

     kmeans = KMeans(n_clusters=i)

     kmeans.fit(data)

    inertias.append(kmeans.inertia_)

plt.plot(range(1,11), inertias, marker='o0")

plt.title('Elbow method")

plt.xlabel('Number of clusters")

plt.ylabel( Inertia’)

plt.show()




#3,The elbow method shows that 2 is a good value for K, so we retrain and visualize the

kmeans = KMeans(n_clusters=2)

kmeans.fit(data)

plt.scatter(x, y, c=kmeans.labels_)

plt.show()




Post a Comment

0Comments

Post a Comment (0)